/*
 * Log.cpp
 *
 *  Created on: 2012-3-28
 *      Author: zhazha
 */

#include "Log.h"
#include <cstdio>
#include <cstdarg>
#include <ctime>

namespace Zha
{

void UpdateLogTimeStamp()
{
    time_t lt; 
    lt=time(NULL);
    g_logTimePtr=localtime(&lt);
    strftime(g_timeStr, 100, "[%F-%H-%M-%S]", g_logTimePtr);
}

int outputText(const char* type, const char* fmt, va_list args )
{
	if (!g_logTimePtr)
	{
		UpdateLogTimeStamp();
	}

	char pTempBuffer[102400];

	int len = 0;

	/* Create the message.... */
	len += vsprintf( &pTempBuffer[len], fmt, args );
	printf( "[%s][%s] %s\n", g_timeStr, type, pTempBuffer );
	return len;
}

void Log(const char* fmt, ...)
{
	va_list args;
	va_start( args, fmt );
	outputText("LOG", fmt, args );
	va_end(args);
}

void Error(const char* fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	outputText("ERROR", fmt, args);
	va_end(args);
	exit(1);
}


}



